package com.ruicar.afs.cloud.product.enums;

/**
 * @author xudongdong
 * @version 1.0
 * @date 2020-05-21
 */

public enum Operator {
    /**
     * 加
     */
    PLUS {
        @Override
        public int priority() {
            return 1;
        }

        @Override
        public double compute(double num1, double num2) {
            return num1 + num2;
        }
    },
    /**
     * 减
     */
    MINUS {
        @Override
        public int priority() {
            return 1;
        }

        @Override
        public double compute(double num1, double num2) {
            return num1 - num2;
        }
    },
    /**
     * 乘
     */
    MULTIPLY {
        @Override
        public int priority() {
            return 2;
        }

        @Override
        public double compute(double num1, double num2) {
            return num1 * num2;
        }
    },
    /**
     * 除
     */
    DIVIDE {
        @Override
        public int priority() {
            return 2;
        }

        @Override
        public double compute(double num1, double num2) {
            return num1 / num2;
        }
    },
    /**
     * 括号
     */
    BRACKETS {
        @Override
        public int priority() {
            return 0;
        }

        @Override
        public double compute(double num1, double num2) {
            return 0;
        }
    };

    /**
     * 对应的优先级
     *
     * @return
     */
    public abstract int priority();

    /**
     * 计算两个数对应的运算结果
     *
     * @param num1 第一个运算数
     * @param num2 第二个运算数
     * @return
     */
    public abstract double compute(double num1, double num2);
}

